--断鹤续凫
local duanhexufu = fk.CreateSkill {
    name = "mcdh_duanhexufu",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

duanhexufu:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target.phase == Player.Draw and target:getHandcardNum() > target.maxHp
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
            local choice = room:askForChoice(target, {"#duanhexufu1:::"..target.hp,"#duanhexufu2"}, self.name, "null")
            if choice == "#duanhexufu1:::"..target.hp then
                local num =  target:getHandcardNum() - target.hp
                room:askForDiscard(target,num, num,false, self.name, false, ".", "#duanhexufu-discard:::"..num, false)
            elseif choice == "#duanhexufu2" then
                room:damage({
                    to = target,
                    damage = 1,
                    skillName = self.name,
                })
            end
    end
})

duanhexufu:addEffect(fk.Death,{
    can_trigger = function(self, event, target, player, data)
            return target == player and player:hasSkill(self.name, false, true)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to =room:askToChoosePlayers(player, {
            targets = player.room.alive_players,
            min_num = 1,
            max_num = 1,
            prompt = "#duanhexufu-choose",
            skill_name = self.name,
            cancelable = false
          })[1]
        room:handleAddLoseSkills(to, self.name,nil, true, false)
    end
})

Fk:loadTranslationTable {
    ["mcdh_duanhexufu"] = "背律",
    [":mcdh_duanhexufu"] = "『断鹤续凫』<br>锁定技，每名角色的摸牌阶段结束时，若其手牌数大于体力上限，则其选择一项：1.将手牌弃置至X张（X为其体力值）；2.受到1点无伤害来源的伤害。当你死亡时，你令一名其他角色获得〖断鹤续凫〗。",
    ["#duanhexufu1"] = "1.将手牌弃置至 %arg 张",
    ["#duanhexufu2"] = "2.受到1点无伤害来源的伤害",
    ["#duanhexufu-discard"] = "断鹤续凫:将手牌弃置至 %arg 张",
    ["#duanhexufu-choose"] = "断鹤续凫:令一名其他角色获得〖断鹤续凫〗"
}

return duanhexufu